package servlets;

import game.Game;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import classes.players.Player;

/**
 * Servlet implementation class WaitingRoom
 */
@WebServlet("/WaitingRoom")
public class WaitingRoom extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		for (Player player : Game.getInstance().getPlayers().values()) {
			response.getWriter().print("<br>User: " + player.getUsername() + " Turn: " + player.getTurnIndex());
		}
		response.setHeader("Refresh", "1; URL=/Pandemic/WaitingRoom");
		if (Game.getTurnIndex() == Game.getNumberOfPlayers()) {
			response.getWriter().print("<form method=\"get\" action=\"/Pandemic/Dispatcher\"><input type=\"submit\" value=\"Start Game!\"></form>");
		}
	}

}
